


# 十种快速排序

class Solution:

    def topKFrequent(self, nums:list[int], k) -> list[int]:
        dict1 = {}
        lenlist = []
        for i in nums:
            if i not in dict1:
                dict1[i] = 1
            
            else:
                dict1[i] = dict1[i] + 1

        for j in dict1:
            lenlist.append(dict1[j])
        # 从大到小排序
        lenlist.sort(reverse=True)

        res = []
        for p in dict1:
            if dict1[p] >= lenlist[k-1]:
                res.append(p)
        
        return res
    
if __name__ == "__main__":

    nums = [1,1,1,2,2,3]
    k = 2

    sol = Solution()
    res = sol.topKFrequent(nums, k)
    print(res)

